/**
 * 面包宵菜单
 */
import tem from './index.html'
import $_fn from '~plugins'
class breadcrumbCtrl {
  constructor($scope,$rootScope) {
      var curUrl = $rootScope._curUrl || window.location.pathname
      var path = curUrl.split('/')
      var LocalMenu =$_fn.getLocal('menu')
      //根据路由的来判断
      $scope.breadcrumbArr = []
      //递归实现查找分类树
      var _breadcrumb = function (breadcrumb) {
          for (var a in path) {
              if (path[a]) {
                  for (var i in breadcrumb) {
                      //只查到二级，如果要更深，修改判断
                      if (breadcrumb[i].state == path[a]) {
                          $scope.breadcrumbArr.push({"name": breadcrumb[i].name, "path": breadcrumb[i].path})
                          break
                      } else {
                          _breadcrumb(breadcrumb[i].children, path[a])
                      }
                  }
              }
          }
      }
      _breadcrumb(LocalMenu)
  }
}
breadcrumbCtrl.$inject = ['$scope','$rootScope']
module.exports = angular.module('directive.breadcrumb', []).directive('breadcrumb', function() {
    return {
        template: tem,
        replace:true,
        scope: {
          options:'@'
        },
        controller: breadcrumbCtrl
    }
}).name